﻿Imports System.IO
Imports System.Threading
Public Class Formbprm
    Private DosCommandOutput As DosCommand.DosCommandOutput '执行Dos程序类
    Private m_Bpip As New CAermod.Bpipprm
    ''' <summary>
    ''' 建筑物下洗对象
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Bpip() As CAermod.Bpipprm
        Get
            Return Me.m_Bpip
        End Get
        Set(ByVal value As CAermod.Bpipprm)
            Me.m_Bpip = value
        End Set
    End Property

    Private Sub Formbprm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.EFlexBuiName.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexCoor.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexPSouce.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)

        Me.ComboBox1.Text = Me.m_Bpip.Process
        TxtTtle.Text = Me.m_Bpip.Title
        TxtUnitsN.Text = Me.m_Bpip.UntisName
        CTunitV.Value = Me.m_Bpip.UntisVale
        TxtGridN.Text = Me.m_Bpip.GridName
        CTGridV.Value = Me.m_Bpip.GridVale

        '建筑物
        BCribil()
        Me.EFlexBuiName.RowSel = Me.EFlexBuiName.Rows.Count - 1
        '每层的顶角坐标
        EFlexCoo()
        '污染源
        PSou()

        Me.EFlexBuiName.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexBuiName.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexBuiName.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

        Me.EFlexCoor.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexCoor.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexCoor.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

        Me.EFlexPSouce.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexPSouce.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexPSouce.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
    End Sub
    ''' <summary>
    ''' 填充污染源EFlexPSouce控件
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub PSou()
        Me.EFlexPSouce.Rows.Count = Me.m_Bpip.ArryBuStack.Length + 1
        For j As Integer = 0 To Me.m_Bpip.ArryBuStack.Length - 1
            Me.EFlexPSouce.SetData(j + 1, 0, Me.m_Bpip.ArryBuStack(j).BrandName)
            Me.EFlexPSouce.SetData(j + 1, 1, Me.m_Bpip.ArryBuStack(j).BrandBase)
            Me.EFlexPSouce.SetData(j + 1, 2, Me.m_Bpip.ArryBuStack(j).BrandHight)
            Me.EFlexPSouce.SetData(j + 1, 3, Me.m_Bpip.ArryBuStack(j).BrandX)
            Me.EFlexPSouce.SetData(j + 1, 4, Me.m_Bpip.ArryBuStack(j).BrandY)
        Next
    End Sub

    '增加污染源
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ReDim Preserve Me.m_Bpip.ArryBuStack(Me.m_Bpip.ArryBuStack.Length)
        Me.m_Bpip.ArryBuStack(Me.m_Bpip.ArryBuStack.Length - 1) = New CAermod.BuStack
        PSou()
    End Sub
    '删除污染源一条记录
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim index As Integer = Me.EFlexPSouce.RowSel - 1
        If index >= 0 Then
            For i As Integer = index To Me.m_Bpip.ArryBuStack.Length - 2
                Me.m_Bpip.ArryBuStack(i) = Me.m_Bpip.ArryBuStack(i + 1)
            Next
            ReDim Preserve Me.m_Bpip.ArryBuStack(Me.m_Bpip.ArryBuStack.Length - 2)
            PSou()
        End If
    End Sub

    Private Sub EFlexBuiName_SelChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles EFlexBuiName.SelChange
        If Me.EFlexBuiName.Rows.Count > 1 Then
            EFlexCoo()
        End If
    End Sub
    '为建筑物数组赋值
    Private Sub EFlexBuiName_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles EFlexBuiName.Validating
        Dim L As Integer = Me.EFlexBuiName.Rows.Count - 1
        For i As Integer = 0 To L - 1
            Me.m_Bpip.ArryBldgi(i).BuildName = Me.EFlexBuiName.GetData(i + 1, 1)
            Me.m_Bpip.ArryBldgi(i).BuildHight = Me.EFlexBuiName.GetData(i + 1, 2)
            '修改的代码--------------------------------------------------------------------------
            Me.m_Bpip.ArryBldgi(i).ArryBuildTire(0).TireHight = Me.EFlexBuiName.GetData(i + 1, 3)
            '修改的代码结束-------------------------------------------------------------------------
        Next
    End Sub
    '增加建筑物一条记录
    Private Sub BCriBild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BCriBild.Click
        ReDim Preserve Me.m_Bpip.ArryBldgi(Me.m_Bpip.ArryBldgi.Length)
        Me.m_Bpip.ArryBldgi(Me.m_Bpip.ArryBldgi.Length - 1) = New CAermod.Bldgi
        Me.m_Bpip.ArryBldgi(Me.m_Bpip.ArryBldgi.Length - 1).BuildName = "建筑物" & Me.m_Bpip.No
        For i As Integer = 0 To Me.m_Bpip.ArryBldgi.Length - 1
            Me.m_Bpip.ArryBldgi(i).BuildStack = "Bpip" & i + 1
        Next
        BCribil()
    End Sub
    ''' <summary>
    ''' 填充EFlexBuiName建筑物
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub BCribil()
        Me.EFlexBuiName.Rows.Count = Me.m_Bpip.ArryBldgi.Length + 1
        For i As Integer = 0 To Me.m_Bpip.ArryBldgi.Length - 1
            Me.EFlexBuiName.SetData(i + 1, 0, Me.m_Bpip.ArryBldgi(i).BuildStack)
            Me.EFlexBuiName.SetData(i + 1, 1, Me.m_Bpip.ArryBldgi(i).BuildName)
            Me.EFlexBuiName.SetData(i + 1, 2, Me.m_Bpip.ArryBldgi(i).BuildHight)
            '修改的代码-----------------------------------------------------------------------------
            Me.EFlexBuiName.SetData(i + 1, 3, Me.m_Bpip.ArryBldgi(i).ArryBuildTire(0).TireHight)
            '修改的代码结束-------------------------------------------------------------------------

        Next
    End Sub

    '删除一条记录,建筑物
    Private Sub BDelBild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BDelBild.Click
        Dim index As Integer = Me.EFlexBuiName.RowSel - 1
        If index >= 0 Then
            For i As Integer = index To Me.m_Bpip.ArryBldgi.Length - 2
                Me.m_Bpip.ArryBldgi(i) = Me.m_Bpip.ArryBldgi(i + 1)
            Next
            ReDim Preserve Me.m_Bpip.ArryBldgi(Me.m_Bpip.ArryBldgi.Length - 2)
            BCribil()
        End If
    End Sub
   

    '单击EFlexCoor事件,给数组赋值
    Private ClickFoor As Integer = 1
    ''' <summary>
    ''' 设置EFlexCoor,角点坐标
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub EFlexCoo()
        If Me.EFlexBuiName.Rows.Count > 1 Then
            Dim xx As Integer = Me.EFlexBuiName.RowSel
            Me.EFlexCoor.Rows.Count = Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner.Length + 1
            Me.UltraGroupBox2.Text = Me.m_Bpip.ArryBldgi(xx - 1).BuildName + "顶点坐标"
            For i As Integer = 0 To Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner.Length - 1
                Me.EFlexCoor.SetData(i + 1, 0, i + 1)
                Me.EFlexCoor.SetData(i + 1, 1, Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(i).x)
                Me.EFlexCoor.SetData(i + 1, 2, Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(i).y)
            Next
        End If
    End Sub

    '增加一条记录,角点坐标
    Private Sub BCrooCr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BCrooCr.Click
        If Me.EFlexBuiName.Rows.Count > 1 Then
            Dim xx As Integer = Me.EFlexBuiName.RowSel
            ReDim Preserve Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner.Length) '顶点增加1
            Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner.Length - 1) = New CAermod.BuildCorner
            EFlexCoo()
        End If
    End Sub
    '为数组赋值,点角坐标
    Private Sub EFlexCoor_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles EFlexCoor.Validating
        If Me.EFlexBuiName.Rows.Count > 1 Then
            Dim L As Integer = Me.EFlexCoor.Rows.Count - 1
            Dim xx As Integer = Me.EFlexBuiName.RowSel
            For i As Integer = 0 To L - 1
                Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(i).x = Me.EFlexCoor.GetData(i + 1, 1)
                Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(i).y = Me.EFlexCoor.GetData(i + 1, 2)
            Next
        End If
    End Sub
    '删除一条记录,角点坐标
    Private Sub BCrooDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BCrooDel.Click
        Dim index As Integer = Me.EFlexCoor.RowSel - 1
        If index >= 0 And Me.EFlexBuiName.RowSel - 1 >= 0 Then
            Dim xx As Integer = Me.EFlexBuiName.RowSel
            For i As Integer = index To Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner.Length - 2
                Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(i) = Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(i + 1)
            Next
            ReDim Preserve Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner(Me.m_Bpip.ArryBldgi(xx - 1).ArryBuildTire(0).ArryBuilCorner.Length - 2)
            Me.EFlexCoo()
        End If
    End Sub

    Private Sub TxtTtle_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TxtTtle.Validating
        Me.m_Bpip.Title = Me.TxtTtle.Text '标题
    End Sub

    Private Sub TxtUnitsN_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TxtUnitsN.Validating
        Me.m_Bpip.UntisName = Me.TxtUnitsN.Text '单位名称
    End Sub

    Private Sub CTunitV_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles CTunitV.Validating
        Me.m_Bpip.UntisVale = CTunitV.Value '单位数值
    End Sub

    Private Sub TxtGridN_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TxtGridN.Validating
        Me.m_Bpip.GridName = Me.TxtGridN.Text '坐标处理标志
    End Sub

    Private Sub CTGridV_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles CTGridV.Validating
        Me.m_Bpip.GridVale = Me.CTGridV.Value '坐标处理标志的值
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'Dim PrjPath As String = My.Computer.FileSystem.GetFileInfo(PrjFileName).DirectoryName
        'Dim strNameLast As String = CAermod.GetFileName(PrjFileName)
        ''MsgBox(My.Application.Info.DirectoryPath)
        '执行aermod程序
        'If My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "Bpipprm.exe") And My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "bpipprm.BAT") Then

        '    Dim txtOut As String
        '    txtOut = Me.m_Bpip.OutPutBp '获取控制流字符串
        '    '打开并写入文件。为了防止aermod占用文件，对访问的文件进行多次试试
        '    Dim IsBusy As Boolean = True
        '    While IsBusy
        '        Try
        '            FileOpen(1, PrjPath & "\" & strNameLast & "\" & "bpipprm.inp", OpenMode.Output)
        '            IsBusy = False
        '        Catch ex As Exception
        '            Thread.Sleep(1000)
        '        End Try
        '    End While
        '    PrintLine(1, txtOut)
        '    FileClose(1)
        '    DosCommandOutput = New DosCommand.DosCommandOutput
        '    DosCommandOutput.CreateNoWindow = False  '是否创建aermod窗体
        '    DosCommandOutput.Execute(PrjPath & "\" & strNameLast & "\", "bpipprm.BAT", "bp.txt")
        '    '显示结果
        '    'Me.m_Bpip.showStr()
        'Else
        '    MsgBox("建筑物下洗程序不存在，请重新安装程序！或与作者联系！")
        'End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        'Me.m_Bpip.showStr()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Me.m_Bpip.Process = Me.ComboBox1.Text '处理过程
    End Sub

    Private Sub EFlexFloor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub OK(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Close()
    End Sub

   
End Class